- Introduction - Using Plotly - Plotly Examples - Using Shiny App - Shiny Examples - Shiny with Plotly Example - Recap - Questions
October 28, 2018
- Introduction - Using Plotly - Plotly Examples - Using Shiny App - Shiny Examples - Shiny with Plotly Example - Recap - Questions
What is Plotly
What is Shiny
URL
Library
install.packages("plotly") or
install the latest development version (on Github) via devtools:devtools::install_github("ropensci/plotly")
2 ways to initiate: - plot_ly() function for datasets - ggplotly() function totransforms a ggplot object into a plotly - ggplotly has a dependency on ggplot2 while plot_ly does not.
library(plotly) library(ggplot2) plot_ly(z = ~volcano)
#options(browser = 'FALSE') t<-plot_ly(midwest, x = ~percollege, color = ~state, type = "box",width = 800, height = 300)%>% layout(margin = list(l = 100)) t
rangeslider(t)
p <- ggplot(txhousing, aes(date, median,
width = 800, height = 300)) +
geom_line(aes(group=city), alpha = 0.2)
p
#options(browser = 'FALSE')
subplot(
p, ggplotly(p, tooltip = "city",
width = 800, height = 300),
ggplot(txhousing, aes(date, median)) + geom_bin2d(),
ggplot(txhousing, aes(date, median)) + geom_hex(),
nrows =2, shareX= TRUE, shareY = TRUE,
titleY = FALSE, titleX = FALSE
)
library(plotly) library(GGally) pm<- ggpairs(iris) ggplotly(pm,width = 800, height = 300)
- Setup Account in https://plot.ly - Get username and secret api key from https://plot.ly/settings/api#/ - Use Sys.setenv to setup username and passowrd keys - Api_create to upload file.
- Use api_dowload(id, username) to download plot from site - Example of dowloading from my account and another public account.
URL
Library
- Uses app.R file to run
- app.R has three components:
- UI is theuser interface object
- server function has to instructions to run build the app
- shinyApp function takes the UI and Server object and creates shiny app
- Setup a shiny account https://www.shinyapps.io
- Get username and user key from https://www.shinyapps.io/admin/#/dashboard
- install rconnect library(rsconnect)
- Deploy web app: rsconnect::deployApp('path/to/your/app')
## Preparing to deploy application...DONE ## Uploading bundle for application: 599265...DONE ## Deploying bundle: 1733349 for application: 599265 ... ## Waiting for task: 569590971 ## building: Parsing manifest ## building: Fetching packages ## building: Installing packages ## building: Installing files ## building: Pushing image: 1790261 ## deploying: Starting instances ## rollforward: Activating new instances ## terminating: Stopping old instances ## Application successfully deployed to https://apag101.shinyapps.io/test2/